package DieSiedler;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.util.Enumeration;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

public class SplashScreen extends JWindow {
	
	private static final long serialVersionUID = 7635611912232227447L;
	
	private int width, height;

	public SplashScreen(String image, String text){	
		this(image, text, 250, 90);
	}
	
	public SplashScreen(String image, String text, int width, int height){
		this.width = width;
		this.height = height;
		
		JPanel contentPane = new JPanel();	   
		contentPane.setLayout(new BorderLayout());	   
		Border bd1 = BorderFactory.createBevelBorder(BevelBorder.RAISED);	    
		Border bd2 = BorderFactory.createEtchedBorder();
		Border bd3 = BorderFactory.createCompoundBorder(bd1, bd2);
		((JPanel)contentPane).setBorder(bd3);
		
		Image imageFile = Toolkit.getDefaultToolkit().createImage(getClass().getResource(image));
		ImageIcon icon = new ImageIcon(imageFile);
		
		//contentPane.add(new JLabel(" ", JLabel.CENTER), BorderLayout.SOUTH);
		contentPane.add(new JLabel(icon, JLabel.CENTER), BorderLayout.CENTER);
		contentPane.add(new JLabel(text, JLabel.CENTER), BorderLayout.NORTH);
		setContentPane(contentPane); 
				
	}
	
	public void showMe(){
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((dim.width / 2)- width / 2, (dim.height / 2) - height / 2);
		//setSize(dim.width / 3, dim.height / 3);
		setSize(width, height);
		setVisible(true);
		//this.setAlwaysOnTop(true);
		//this.setFocusable(true);
	}
		
	public void stopShowing(){
		setVisible(false);
	}
	
	public void showFor(int millies){
		showMe();
		try {
			Thread.sleep(millies);
		} catch (InterruptedException e) {
			// fehler
		}
		stopShowing();
		
	}
}